#include "USBClientConnector.h"
#include "soft_usb.h"

void USBClientConnector::destory() {

    clear();
}

void USBClientConnector::clear() {
    _status = 0;        // 连接状态    (-1:连接失败 0:未连接 1:已连接 2：已识别(HID))
    cfgNum = 0;         // USB接口号
    interfaceNum = 0;   // USB接口号
    epMin = 0;          // 该接口下最小端点号
    epMax = 0;          // 该接口下最大端点号
    _type = 0;          //  (0:未知  1：键盘 2:鼠标)
    _keyboard_mode = 0; // 0: 美式键盘; 1:日式键盘
}

void USBClientConnector::setUSBClientConnectorCallbacks(USBClientConnectorCallbacks *pCallbacks) {
    _pCallbacks = pCallbacks;
}

void USBClientConnector::setOnRecvData(setOnRecvData_t cb) {
    onRecvDataCallback = cb;
}

void USBClientConnector::onRecvData(uint8_t *dataBuf, int nLen) {

    onRecvDataCallback(this, dataBuf, nLen);
}

// 控制键盘灯
void USBClientConnector::setLED(uint8_t flags) {
    _SUSB.usbSetupOut(usbNum, (uint8_t *)SetupHIDSetReport, &flags, 1);
}